'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 1_home_work.py
* @Time: 2025/10/23
* @All Rights Reserve By Brtc
'''
def is_valid(s:str)->bool:
    if len(s)%2 != 0:
        return False

    pairs = {")":"(","}":"{","]":"["}
    stack = list()

    for ch in s:
        if ch in pairs:
            if not stack or stack[-1] != pairs[ch]:
                return False
            stack.pop()
        else:
            stack.append(ch)
    return not stack

if __name__ == "__main__":
    s = "{}{}{}{}{(({))}"
    print(is_valid(s))